package com.wanyang.aliyun.configure;

import com.wanyang.utils.YamlUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.List;

@Data
@Slf4j
public class SmsProperties {
    private static SmsProperties instance;

    private String mode;
    private List<Template> templates;

    public static SmsProperties getInstance() {

        if (instance != null)
            return instance;

        synchronized (SmsProperties.class) {
            if (instance == null) {
                try {
                    SmsProperties smsProperties = YamlUtil.loadConf("/sms.yml", SmsProperties.class);
                    instance = smsProperties;
                } catch (IOException e) {
                    log.error(e.getMessage(), e);
                }
            }
        }

        return instance;
    }

    private SmsProperties() {}

    @Data
    public static class Template {
        private String templateCode;
        private String signName;
        private String type;
    }

    public boolean isTestMode() {
        return "test".equals(mode);
    }

}
